package com.qianfeng.goods.service;

import java.util.List;

import com.qianfeng.goods.bean.TypeBean;
import com.qianfeng.goods.dao.TypeDao;
import com.qianfeng.utils.DBUtils;

public class TypeService {
	
	
	
	
	public List<TypeBean> getListAll(){
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		List<TypeBean> list= typeDao.getListAll();
		DBUtils.release();
		return list;
		
	}
	/*
	 * 查询所有的商品分类信息
	*/
	public List<TypeBean> getList(TypeBean bean){
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		List<TypeBean> list= typeDao.getList(bean);
		DBUtils.release();
		return list;	
	}
	public int getCount(TypeBean bean){
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		int num=typeDao.getCount(bean);
		DBUtils.release();
		return num;
	}
	/**
	  * 根据id删除分类
	 * @param id
	 * @return
	 */
	public boolean deleteById(long id) {
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		int num = typeDao.deleteById(id);
		DBUtils.release();
		return num>0;
	}
	/**
	 * 根据id查询分类的详细信息
	 * @param id
	 * @return
	 */
	public TypeBean getById(long id) {
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		TypeBean typeBean=typeDao.getById(id);
		DBUtils.release();
		return typeBean;
	}
	
	public boolean updateType(TypeBean bean) {
		
		TypeDao typeDao = DBUtils.getMapper(TypeDao.class);
		int num = 0;
		if(bean.getId()>0) {
			num = typeDao.updateById(bean);
		}else {
			bean.setCreate_time(System.currentTimeMillis());
			num = typeDao.saveType(bean);
		}
		DBUtils.release();
		return num > 0;
	}
	
}
